package com.scoy.honeymei.dialog;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;

import com.scoy.honeymei.R;
import com.scoy.honeymei.utils.GlideImgUtil;

import java.util.List;


public class ImgVPAdapter extends PagerAdapter {
    private Context context;
    private List<String> paths;

    public ImgVPAdapter(Context context, List<String> paths) {
        this.context = context;
        this.paths = paths;
    }

    @Override
    public int getCount()  {
        return paths.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;
    }

    @NonNull
    @Override
    public Object instantiateItem(ViewGroup container, final int position) {
        ImageView iv_img = (ImageView) LayoutInflater.from(context).inflate(R.layout.item_picfull_pv, null);

        GlideImgUtil.glidePicNo(context, paths.get(position),iv_img);
        iv_img.setOnClickListener(v -> {
            if(allClickListener!=null){
                allClickListener.allclick(position);
            }
        });
        container.addView(iv_img);
        return iv_img;
    }


    @Override
    public void destroyItem(ViewGroup container, int position, @NonNull Object object) {
        container.removeView((View) object);
    }

   public interface AllClickListener{
        void allclick(int pos);
    }

    private AllClickListener allClickListener;

    public void setAllClickListener(AllClickListener allClickListener) {
        this.allClickListener = allClickListener;
    }
}
